package com.ruoyi.score.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.score.mapper.ScoreDetailMapper;
import com.ruoyi.score.domain.ScoreDetail;
import com.ruoyi.score.service.IScoreDetailService;

/**
 * 积分明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@Service
public class ScoreDetailServiceImpl implements IScoreDetailService 
{
    @Autowired
    private ScoreDetailMapper scoreDetailMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询积分明细
     * 
     * @param id 积分明细主键
     * @return 积分明细
     */
    @Override
    public ScoreDetail selectScoreDetailById(Long id)
    {
        return scoreDetailMapper.selectScoreDetailById(id);
    }

    /**
     * 查询积分明细列表
     * 
     * @param scoreDetail 积分明细
     * @return 积分明细
     */
    @Override
    public List<ScoreDetail> selectScoreDetailList(ScoreDetail scoreDetail)
    {
        List<ScoreDetail> list = scoreDetailMapper.selectScoreDetailList(scoreDetail);
        if (list != null) {
            for (ScoreDetail item: list) {
                SysUser sysUser = sysUserMapper.selectUserById(item.getUserId());
                item.setSysUser(sysUser);
            }
        }
        return list;
    }
    /**
     * 新增积分明细
     * 
     * @param scoreDetail 积分明细
     * @return 结果
     */
    @Override
    public int insertScoreDetail(ScoreDetail scoreDetail)
    {
        return scoreDetailMapper.insertScoreDetail(scoreDetail);
    }

    /**
     * 修改积分明细
     * 
     * @param scoreDetail 积分明细
     * @return 结果
     */
    @Override
    public int updateScoreDetail(ScoreDetail scoreDetail)
    {
        scoreDetail.setUpdateTime(DateUtils.getNowDate());
        return scoreDetailMapper.updateScoreDetail(scoreDetail);
    }

    /**
     * 批量删除积分明细
     * 
     * @param ids 需要删除的积分明细主键
     * @return 结果
     */
    @Override
    public int deleteScoreDetailByIds(Long[] ids)
    {
        return scoreDetailMapper.deleteScoreDetailByIds(ids);
    }

    /**
     * 删除积分明细信息
     * 
     * @param id 积分明细主键
     * @return 结果
     */
    @Override
    public int deleteScoreDetailById(Long id)
    {
        return scoreDetailMapper.deleteScoreDetailById(id);
    }
}
